package com.aizhixin.lab.company.service;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.aizhixin.lab.common.core.ApiReturnConstants;
import com.aizhixin.lab.common.core.DataValidity;
import com.aizhixin.lab.company.domain.SystemSetDomain;
import com.aizhixin.lab.company.entity.SystemSet;
import com.aizhixin.lab.company.entity.User;
import com.aizhixin.lab.company.repository.SystemSetRepository;

@Slf4j
@Service
@Transactional
public class SystemSetService {
	@Autowired
	private SystemSetRepository systemSetRepository;

	public Map<String, Object> save(SystemSetDomain domain) {
		Map<String, Object> result = new HashMap<>();
		SystemSet systemSet = null;
		if (null != domain.getId() && domain.getId() > 0) {
			systemSet = systemSetRepository.findOne(domain.getId());
		}
		if (null == systemSet) {
			systemSet = new SystemSet();
		}
		BeanUtils.copyProperties(domain, systemSet);
		systemSetRepository.save(systemSet);
		result.put(ApiReturnConstants.SUCCESS, true);

		return result;
	}
	
	public Map<String, Object> getInfor() {
		Map<String, Object> result = new HashMap<>();
		SystemSetDomain domain = new SystemSetDomain();
		List<SystemSet>	systemSetList = systemSetRepository.findAllByDeleteFlag(DataValidity.VALID.getState());
		if (!systemSetList.isEmpty()) {
			SystemSet systemSet = systemSetList.get(0);
			BeanUtils.copyProperties(systemSet, domain);
			result.put(ApiReturnConstants.DATA, domain);
		}
		
		result.put(ApiReturnConstants.SUCCESS, true);

		return result;
	}
}
